package day7;

import java.util.*;
public class TestDemo12 {
    public static void main(String[] args) {

    }

    public class Parenthesis {
        public boolean chkParenthesis(String A, int n) {
            // write code here
            if(n % 2 != 0) return false;
            Stack<Character> stack = new Stack<>();
            for (char c:A.toCharArray()) {
                if(c == '(') {
                    stack.push(c);
                } else if(c == ')') {
                    if(stack.isEmpty()) {
                        return false;
                    } else {
                        if(stack.peek() == '(') {
                            stack.pop();
                        } else {
                            return false;
                        }
                    }
                } else {
                    return false;
                }
            }
            return stack.isEmpty();
        }
    }
}
